package duplicateZeros;

import java.util.Stack;

public class Solution {
    public void duplicateZeros(int[] arr) {
        Stack<Integer> stack = new Stack<>();
        for (int i = 0; i < arr.length; i++) {
            if(arr[i] == 0){
                stack.push(arr[i]);
            }
            stack.push(arr[i]);
            if(stack.size()>=arr.length) {
                break;
            }
        }
        if(stack.size()>arr.length) {
            stack.pop();
        }
        for (int i = arr.length-1; i >=0 ; i--) {
            arr[i] = stack.pop();
        }
    }
}
